/*
 * Created on 30/ago/07
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package it.unibo.deis.lia.mmhc.pas;

//import it.unibo.deis.lia.location.LocationOss;
import it.unibo.deis.lia.mmhc.util.*; //import it.unibo.deis.lia.networkInterface.*;

import java.util.Vector;

public class SimplePathMetric implements PathMetric {

	private float enduranceThreshold;

	public SimplePathMetric(float enduranceThreshold) {
		// inserire i requisiti
		this.enduranceThreshold = enduranceThreshold;
	}

	public Path evaluate(/*
						 * float mobilityDegree,int
						 * mobilityState,Vector<LocationOss> joints,
						 */Vector<Path> suitablePaths) throws Exception {
		Path bestPath = null;
		float bestEndurance = -1;
		for (int i = 0; i < suitablePaths.size(); i++) {
			Path path = suitablePaths.elementAt(i);
			Connector connector = path.getChannel().getConnector();

			float endurance = connector.getEnduranceEstimation();
			if (endurance >= enduranceThreshold && endurance > bestEndurance) {
				bestEndurance = endurance;
				bestPath = path;
			}

			/*
			 * float endurance=-1; if(connector.isFixed()){
			 * endurance=(1-mobilityDegree
			 * )*connector.getLocalNetworkInterface().getCoverageRange(); }
			 * else{ float joint=-1; for(int
			 * j=0;j<joints.size()&&joint==-1;j++){ LocationOss
			 * jointPeer=joints.elementAt(j);
			 * if(jointPeer.getId().equals(connector
			 * .getConnectorDescription().getId())){
			 * joint=(float)jointPeer.getValue(); } } if(joint!=-1)
			 * endurance=joint
			 * *connector.getLocalNetworkInterface().getCoverageRange(); }
			 * if(endurance>=enduranceThreshold && endurance>bestEndurance){
			 * bestEndurance=endurance; bestChannel=channel; }
			 * /*GenericNetworkInterface
			 * networkInterface=connector.getLocalNetworkInterface();
			 * if(networkInterface instanceof IEEE80211){ //IEEE80211
			 * ieee80211=(IEEE80211)networkInterface; bestChannel=channel; }
			 * else if(networkInterface instanceof Bluetooth){ //Bluetooth
			 * bluetooth=(Bluetooth)networkInterface; if(channel==null){
			 * bestChannel=channel; } } else{ throw new
			 * Exception("Unknown network interface: "+networkInterface); }
			 */
		}
		return bestPath;
	}
}
